//
//  main.m
//  StrToDic
//
//  Created by 준기 반 on 11. 5. 26..
//  Copyright 2011 한성대학교. All rights reserved.
//



//
//
//
//  NSDictionary형태로 리턴하는방법을 모르겠..
//	
//
//

#import <Foundation/Foundation.h>
NSMutableDictionary * HeartSTD(NSString *string){  //하트콘  
	
	NSArray *arr;
	NSDateComponents *tempdate=[[NSDateComponents alloc]init];
	NSCalendar *tempcal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@"♡"];
	[tempdate setYear:[[[arr objectAtIndex:3] substringToIndex:4]intValue]];
	[tempdate setMonth:[[[arr objectAtIndex:3] substringWithRange:NSMakeRange(4,2)]intValue]];
	[tempdate setDay:[[[arr objectAtIndex:3] substringWithRange:NSMakeRange(6,2)]intValue]];
	NSDate *date=[tempcal dateFromComponents:tempdate];
	//[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:1]];
	//[dic setValue:[arr objectAtIndex:2] forKey:[title objectAtIndex:2]];
	[dic setValue:date forKey:[title objectAtIndex:3]];
	[dic setValue:[arr objectAtIndex:4] forKey:[title objectAtIndex:4]];
	[dic setValue:[arr objectAtIndex:5] forKey:[title objectAtIndex:5]];
	return dic;
}
NSMutableDictionary * TitekMonSTD(NSString *string){  //티켓몬스터
	NSString *tempstr;
	NSArray *arr;
	NSString *datestr;
	NSDateComponents *tempdate=[[NSDateComponents alloc]init];
	NSCalendar *tempcal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date=[NSDate date];
	datestr=[NSString stringWithFormat:@"%@",date];
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@":"];
	NSArray *temparr;
	//temparr=[[arr objectAtIndex:0] componentsSeparatedByString:@"유"];
	//[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:0]];
	temparr=[[arr objectAtIndex:1] componentsSeparatedByString:@" "];
	temparr=[[temparr objectAtIndex:0] componentsSeparatedByString:@"~"];
	temparr=[[temparr objectAtIndex:1] componentsSeparatedByString:@"."];
	[tempdate setMonth:[[temparr objectAtIndex:0]intValue]];
	[tempdate setDay:[[temparr objectAtIndex:1]intValue]];
	[tempdate setYear:[[datestr substringToIndex:4]intValue]];
	date=[tempcal dateFromComponents:tempdate];
	[dic setValue:date forKey:[title objectAtIndex:3]];
	temparr=[[arr objectAtIndex:2] componentsSeparatedByString:@"("];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:1]];
	tempstr=[temparr objectAtIndex:1];
	temparr=[tempstr componentsSeparatedByString:@" "];
	[dic setValue:[temparr objectAtIndex:0] forKey:[title objectAtIndex:4]];
	tempstr=[temparr objectAtIndex:1];
	temparr=[tempstr componentsSeparatedByString:@")"];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:5]];
	return dic;
	
}
NSMutableDictionary * CupangSTD(NSString *string){  //쿠팡
	int count=0;
	NSString *tempstr;
	NSString *ttempstr=@" ";
	NSArray *arr;
	NSDateComponents *tempdate=[[NSDateComponents alloc]init];
	NSCalendar *tempcal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	NSArray *temparr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@"]"];
	tempstr=[arr objectAtIndex:0];
	temparr=[tempstr componentsSeparatedByString:@" "];
	[dic setValue:[temparr objectAtIndex:1] forKey:[title objectAtIndex:1]];
	//tempstr=[NSString stringWithFormat:@"%@]",[temparr objectAtIndex:0]];
	//[dic setValue:tempstr forKey:[title objectAtIndex:0]];
	tempstr=[arr objectAtIndex:1];
	arr=[tempstr componentsSeparatedByString:@"/"];
	for(NSString *s in arr){
		count++;
	}
	[tempdate setYear:[[[arr objectAtIndex:count-1]substringToIndex:4]intValue]];
	[tempdate setMonth:[[[arr objectAtIndex:count-1]substringWithRange:NSMakeRange(5,2)]intValue]];
	[tempdate setDay:[[[arr objectAtIndex:count-1]substringWithRange:NSMakeRange(8,2)]intValue]];
	NSDate *date=[tempcal dateFromComponents:tempdate];
	[dic setValue:date forKey:[title objectAtIndex:3]];
	tempstr=[NSString stringWithFormat:@"%@",[arr objectAtIndex:0]];
	for(int i=1;i<count-1;i++){
		ttempstr=[NSString stringWithFormat:@"%@%@",ttempstr,[NSString stringWithFormat:@"/%@",[arr objectAtIndex:i]]];    //여기서 멈춤
	}
	tempstr=[NSString stringWithFormat:@"%@%@",tempstr,ttempstr];
	[dic setValue:tempstr forKey:[title objectAtIndex:4]];
	return dic;
}
NSMutableDictionary * GiftiConSTD(NSString *string){  //기프티콘
	NSArray *arr;
	NSArray *temparr;
	NSString *tempstr;
	NSString *datestr;
	NSDateComponents *tempdate=[[NSDateComponents alloc]init];
	NSCalendar *tempcal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date=[NSDate date];
	datestr=[NSString stringWithFormat:@"%@",date];
	
	
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@" "];
	//[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	tempstr=[NSString stringWithFormat:@"%@ %@",[arr objectAtIndex:1],[arr objectAtIndex:2]];
	[dic setValue:tempstr forKey:[title objectAtIndex:5]];
	temparr=[[arr objectAtIndex:3] componentsSeparatedByString:@":"];
	[dic setValue:[temparr objectAtIndex:1] forKey:[title objectAtIndex:4]];
	[dic setValue:[[arr objectAtIndex:4]substringWithRange:NSMakeRange(1,12)] forKey:[title objectAtIndex:1]];
	temparr=[[arr objectAtIndex:5] componentsSeparatedByString:@"."];
	[tempdate setMonth:[[[temparr objectAtIndex:0] substringWithRange:NSMakeRange(1,2)]intValue]];
	[tempdate setDay:[[temparr objectAtIndex:1] intValue]];
	[tempdate setYear:[[datestr substringToIndex:4]intValue]];
	date=[tempcal dateFromComponents:tempdate];
	[dic setValue:date forKey:[title objectAtIndex:3]];
	return dic;
	
}
NSMutableDictionary * GiftiShowSTD(NSString *string){ //기프티쇼
	NSArray *arr;
	NSArray *temparr;
	NSString *datestr;
	NSDateComponents *tempdate=[[NSDateComponents alloc]init];
	NSCalendar *tempcal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
	NSDate *date=[NSDate date];
	datestr=[NSString stringWithFormat:@"%@",date];
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@" "];
	//[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:5]];
	[dic setValue:[[arr objectAtIndex:3]substringWithRange:NSMakeRange(1,13)] forKey:[title objectAtIndex:1]];
	temparr=[[arr objectAtIndex:4] componentsSeparatedByString:@"/"];
	temparr=[[temparr objectAtIndex:0]componentsSeparatedByString:@"월"];
	temparr=[[temparr objectAtIndex:0]componentsSeparatedByString:@"~"];
	[tempdate setMonth:[[temparr objectAtIndex:1]intValue]];
	temparr=[[arr objectAtIndex:4] componentsSeparatedByString:@"/"];
	[tempdate setDay:[[temparr objectAtIndex:1]intValue]];
	[tempdate setYear:[[datestr substringToIndex:4]intValue]];
	date=[tempcal dateFromComponents:tempdate];
	[dic setValue:date forKey:[title objectAtIndex:3]];
	arr=[[arr objectAtIndex:2] componentsSeparatedByString:@":"];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:4]];
	return dic;
}

int main(int argc, char *argv[]) {
    NSString *tstr=@"[티몬/간지나라/더보이/빈티지환]유효기간:5.27.14시~8.31 티 켓:TPG007510121 ([전국]스타일의진리'간지나라/더보이/빈티지환' 장)";
	NSString *hstr=@"하트콘♡998000000000♡1개♡20100000까지♡스타벅스♡커피이름";
	NSString *cstr=@"[쿠팡 208690299088]엔제리너스/충남/충북-청주산남점/2011.06.30까지";
	NSString *gstr=@"[기프티콘] 아메리카노 Tall 교환처:스타벅스 <999000000000> ~06.2";
	NSString *gsstr=@"[기프티쇼] 제품명 교환처:GS25 <900-0000-0000> ~6월/2일";
	NSMutableDictionary *dict=[NSMutableDictionary dictionary];
	dict=HeartSTD(hstr);
	for(NSString *key in dict){
		NSLog(@"%@:%@",key,[dict objectForKey:key]);
	}
	dict=TitekMonSTD(tstr);
	for(NSString *key in dict){
		NSLog(@"%@:%@",key,[dict objectForKey:key]);
	}
	dict=CupangSTD(cstr);
	for(NSString *key in dict){
		NSLog(@"%@:%@",key,[dict objectForKey:key]);
	}
	dict=GiftiConSTD(gstr);
	for(NSString *key in dict){
		NSLog(@"%@:%@",key,[dict objectForKey:key]);
	}
	dict=GiftiShowSTD(gsstr);
	for(NSString *key in dict){
		NSLog(@"%@:%@",key,[dict objectForKey:key]);
	}
	
}

